using System.Windows;
using System.Windows.Input;
using CodRevit.ViewModels;

namespace CodRevit.Views
{
    public partial class SimulateSelectView : Window
    {
        public SimulateSelectView()
        {
            InitializeComponent();
            
            // 订阅 ViewModel 的关闭请求事件
            this.DataContextChanged += (s, e) =>
            {
                if (DataContext is SimulateSelectViewModel viewModel)
                {
                    viewModel.RequestClose = (result) =>
                    {
                        DialogResult = result;
                        Close();
                    };
                }
            };
        }

        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                // ESC键处理由ViewModel的Cancel命令处理
                if (DataContext is SimulateSelectViewModel viewModel)
                {
                    viewModel.CancelCommand.Execute(null);
                }
            }
            base.OnKeyDown(e);
        }
    }
}